Drug use

Column

Marijuana use Vs % of marijuana lyric at national level

Column

Marijuana

Other than marijuana

Binge drinking

Risk perception

Annual incidence

---
title: "Drug & Music dashboard"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: scroll
    source_code: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
library(plotly)
library(tidyverse)
```

```{r}
songs_abuse=read_csv("./data/songs_abuse.csv")
```

Drug use
=======================================================================
- In this page, we analyzed the Drug Use and Health Small Area Estimation Dataset from 1999 to 2019 (right), as well as the relationship between the Marijuana use and marijuana lyric trends (left).

  - The relationship between the Marijuana use and marijuana lyric trends

  - Mean prevalence rates (%) of drug use by age group (including: Marijuana/other than Marijuana/binge drinking use)

  - Risk perception on smoking marijuana once a month

  - Annual incidence of first use of marijuana

Column {data-width=450}
-----------------------------------------------------------------------

### Marijuana use Vs % of marijuana lyric at national level

```{r}
songs_abuse_plot=
  songs_abuse%>%
  filter(stname=="National", outcome=="Marijuana use in the past month")%>%
  group_by(year)%>%
  ggplot(aes(x = p_lyrics, y = bsae, color = agegrp)) +
    geom_point() +
    geom_smooth(aes(group = agegrp), se = F) +
   labs(x="% of marijuana lyric",
         y = "Marijuana use in the past(%)",
         color = "agegroup")

ggplotly(songs_abuse_plot)
```

Column {.tabset data-width=550}
-----------------------------------------------------------------------

### Marijuana

```{r}
marijuana_plot=
songs_abuse%>%
  filter(outcome=="Marijuana use in the past month",area==0)%>%
  group_by(year,agegrp)%>%
  summarize(
  mean_bsae = mean(bsae)
)%>%
  ggplot(aes(x = year, y = mean_bsae)) +
  geom_smooth(aes(color = agegrp), alpha = .5)+
    labs(title = "Mean prevalence rates (%) of Marijuana use by age group",
         y = "Mean prevalence rates of Marijuana use (%) ",
         color = "agegroup")

ggplotly(marijuana_plot)
```

### Other than marijuana

```{r}
otherthan_marijuana_plot=
  songs_abuse%>%
  filter(outcome=="Illicit drugs other than marijuana use in the last month",area==0)%>%
  group_by(year,agegrp)%>%
  summarize(
  mean_bsae = mean(bsae)
)%>%
  ggplot(aes(x = year, y = mean_bsae)) +
  geom_smooth(aes(color = agegrp), alpha = .5)+
  labs(title = "Mean prevalence rates (%) of illicit durg other than marijuana by age group",
         y = "Mean prevalence rates (%) of illicit durg other than marijuana",
         color = "agegroup")

ggplotly(otherthan_marijuana_plot)
```

### Binge drinking
```{r}
bingedrink_plot=
songs_abuse%>%
  filter(outcome=="Binge drinking in the last month",area==0)%>%
  group_by(year,agegrp)%>%
  summarize(
  mean_bsae = mean(bsae)
)%>%
  ggplot(aes(x = year, y = mean_bsae)) +
  geom_smooth(aes(color = agegrp), alpha = .5)+
  labs(title = "Mean prevalence rates (%) of binge drinking in the past by age group",
         y = "Mean binge drinking (%) in the past",
         color = "agegroup")

ggplotly(bingedrink_plot)
```


### Risk perception
```{r}
risk_plot=
songs_abuse%>%
  filter(outcome=="Risk perception on smoking marijuana once a month",area==0)%>%
  group_by(year,agegrp)%>%
  summarize(
  mean_bsae = mean(bsae)
)%>%
  ggplot(aes(x = year, y = mean_bsae)) +
  geom_smooth(aes(color = agegrp), alpha = .5)+
  labs(title = "Risk perception on smoking marijuana by age group",
         y = "Risk perception on smoking marijuana(%) ",
         color = "agegroup")

ggplotly(risk_plot)
```

### Annual incidence
```{r}
incidence_plot=
songs_abuse%>%
  filter(outcome=="Annual incidence of first use of marijuana",area==0)%>%
  group_by(year,agegrp)%>%
  summarize(
  mean_bsae = mean(bsae)
)%>%
  ggplot(aes(x = year, y = mean_bsae)) +
  geom_smooth(aes(color = agegrp), alpha = .5)+
  labs(title = "Annual incidence of first use of marijuana by age group",
         y = "Annual incidence of first use of marijuana (%) ",
         color = "agegroup")
ggplotly(incidence_plot)
```

Popular music
=======================================================================
- In this page, we analyzed the popular music trend from 1999 to 2019 (left), as well as the trend of substance use and the trend of substance description during this period at national level (right).

  - Hip-hop/R&B and rap music are getting popular, while country music and rock music are getting less hot.
  - Generally, substances are more and more often mentioned.
  - Rap music mentioned substances most.
  
  - People aged 26 years and older are getting more likely to binge drinking, though people aged 18-25 years old drink the most.
  - With the increasing proportion of marijuana description in popular songs, more and more people aged 18-25 years used marijuana.
  - With the increasing proportion of marijuana description in popular songs, people get less likely to consider using marijuana once a month is risky. People aged 18-25 years old are least likely to think so.
  - The trend in other illicit drugs are not obvious.

```{r }
genly = read_csv("./data/genly_billboard.csv", col_names = TRUE) %>%
  mutate(gen_cate = str_remove(gen_cate, "gen_"),
         gen_cate = str_replace(gen_cate,"hiphop", "hip-hop/RnB"),
         lyr_des = as_factor(lyr_des),
         gen_cate = as_factor(gen_cate)) %>%
  select(-lyr_gen)

songs_abuse = read_csv("./data/songs_abuse.csv", col_names = TRUE) %>%
  filter(area == 0) %>%
  mutate(agegrp = as_factor(agegrp),
         outcome = as_factor(outcome)) %>%
  select(-n_lyrics,-total,-stname,-pyearnm)
```

Column {.tabset data-width=600}
-----------------------------------------------------------------------

### Genre popularity trend

```{r}
genly %>%
  filter(lyr_des == "alcohol") %>%
  mutate(text_label = str_c("Genre: ", gen_cate, "\nPopularity: ", round(p_genre, 2), "% \n(95% CI: ",round(p_gen_lci,2),"% - ",round(p_gen_uci,2),"%)")) %>%
  rename("Percentage" = "p_genre") %>%
  plot_ly(
    x = ~ year,
    y = ~ Percentage,
    color = ~ gen_cate,
    text = ~text_label,
    type = "scatter",
    alpha = 0.7
  ) %>%
    add_paths() %>%
    add_ribbons( ymin = ~ p_gen_lci,
                 ymax = ~ p_gen_uci,
                 alpha = 0.3)
```

### Substance description trend
```{r}
genly %>%
  filter(gen_cate == "country") %>%
  mutate(text_label = str_c("Substance mentioned: ", lyr_des, "\nPopularity: ", round(p_lyrics, 2), "% \n(95% CI: ",round(p_lyr_lci,2),"% - ",round(p_lyr_uci,2),"%)")) %>%
  rename("Percentage" = "p_lyrics") %>%
  plot_ly(
    x = ~ year,
    y = ~ Percentage,
    color = ~ lyr_des,
    text = ~text_label,
    type = "scatter",
    alpha = 0.7
  ) %>%
    add_paths() %>%
    add_ribbons( ymin = ~ p_lyr_lci,
                 ymax = ~ p_lyr_uci,
                 alpha = 0.3)
```

### Substance x Genres

```{r}
genly %>%
  group_by(gen_cate) %>%
  mutate(text_label = str_c("Genre: ", gen_cate,
                            "\nSubstance mentioned: ", lyr_des,
                            "\nPopularity: ", round(p_genre, 2), "% \n(95% CI: ",round(p_gen_lci,2),"% - ",round(p_gen_uci,2),"%)")) %>%
  rename("Percentage" = "p_lyrgen") %>%
  do( p = plot_ly(.,
    x = ~ year,
    y = ~ Percentage,
    color = ~ lyr_des,
    text = ~text_label,
    type = "scatter",
    alpha = 0.7) %>%
    add_paths() %>%
    add_ribbons( ymin = ~ p_lyrgen_lci,
                 ymax = ~ p_lyrgen_uci,
                 alpha = 0.3) %>%
    add_annotations(text = ~gen_cate,
                    showarrow = FALSE,
                    x = 2010, y = 80,
                    xanchor = "middle",
                    yanchor = "top",
                    font = list(size = 15))) %>%
  subplot(nrows = 2, shareX = TRUE, shareY = TRUE)
```



Column {.tabset data-width=600}
-----------------------------------------------------------------------

### Binge drinking

```{r}
songs_abuse %>%
  filter(outcome == "Binge drinking in the last month" & lyr_des == "alcohol") %>%
  mutate(text_label = str_c("Year: ", year,
                            "\nAge group: ", agegrp,
                            "\nBinge drinking(%, 95% CI): ", round(bsae, 2), " (", round(low_sae, 2)," - ",round(up_sae, 2),")",
                            "\nAlcohol description(%, 95% CI):", round(p_lyrics, 2), " (", round(p_lci, 2)," - ",round(p_uci, 2),")")) %>%
  plot_ly(x = ~ year,
          y = ~ bsae,
          color = ~ agegrp,
          text = ~ text_label,
          type = "scatter",
          mode = "paths",
          alpha = 0.7) %>%
  add_ribbons(ymin = ~ low_sae, ymax = ~ up_sae, alpha = 0.3) %>%
  add_trace(x = ~ year, y = ~ p_lyrics, type = "scatter", mode = "paths", text = ~ paste("Alcohol description (%): ", round(p_lyrics,2))) %>%
  add_ribbons(ymin = ~ p_lci, ymax = ~ p_uci, alpha = 0.3) %>%
  layout(title = "The relationship between \nbinge drinking in the last month and alcohol description in the lyrics,\nat national level",
          yaxis = list(title = "Percentage(%)"),
         legend = list(title = list(text = 'Grey line: \n  alcohol description \nin the lyrics(%, 95% CI) \n \nAge group')))
  
```

### Marijuana usage

```{r}
songs_abuse %>%
  filter(outcome == "Marijuana use in the past month" & lyr_des == "marijuana") %>%
  mutate(text_label = str_c("Year: ", year,
                            "\nAge group: ", agegrp,
                            "\nMarijuana use(%, 95% CI): ", round(bsae, 2), " (", round(low_sae, 2)," - ",round(up_sae, 2),")",
                            "\nMarijuana description(%, 95% CI):", round(p_lyrics, 2), " (", round(p_lci, 2)," - ",round(p_uci, 2),")")) %>%
  plot_ly(x = ~ year,
          y = ~ bsae,
          color = ~ agegrp,
          text = ~ text_label,
          type = "scatter",
          mode = "paths",
          alpha = 0.7) %>%
  add_ribbons(ymin = ~ low_sae, ymax = ~ up_sae, alpha = 0.3) %>%
  add_trace(x = ~ year, y = ~ p_lyrics, type = "scatter", mode = "paths", text = ~ paste("Marijuana description (%): ", round(p_lyrics,2))) %>%
  add_ribbons(ymin = ~ p_lci, ymax = ~ p_uci, alpha = 0.3) %>%
  layout(title = "The relationship between \nmarijuana use in the last month and alcohol description in the lyrics,\nat national level",
         yaxis = list(title = "Percentage(%)"),
         legend = list(title = list(text = 'Grey line: \n  marijuana description \nin the lyrics(%, 95% CI) \n \nAge group')))
```

### Marijuana perception

```{r}
songs_abuse %>%
  filter(outcome == "Risk perception on smoking marijuana once a month" & lyr_des == "marijuana") %>%
  mutate(text_label = str_c("Year: ", year,
                            "\nAge group: ", agegrp,
                            "\nMarijuana perception(%, 95% CI): ", round(bsae, 2), " (", round(low_sae, 2)," - ",round(up_sae, 2),")",
                            "\nMarijuana description(%, 95% CI):", round(p_lyrics, 2), " (", round(p_lci, 2)," - ",round(p_uci, 2),")")) %>%
  plot_ly(x = ~ year,
          y = ~ bsae,
          color = ~ agegrp,
          text = ~ text_label,
          type = "scatter",
          mode = "paths",
          alpha = 0.7) %>%
  add_ribbons(ymin = ~ low_sae, ymax = ~ up_sae, alpha = 0.3) %>%
  add_trace(x = ~ year, y = ~ p_lyrics, type = "scatter", mode = "paths", text = ~ paste("Marijuana description (%): ", round(p_lyrics,2))) %>%
  add_ribbons(ymin = ~ p_lci, ymax = ~ p_uci, alpha = 0.3) %>%
  layout(title = "The relationship between \nrisk percetion on using marijuana once a month and marijuana description in the lyrics,\nat national level",
        yaxis = list(title = "Percentage(%)"),
         legend = list(title = list(text = 'Grey line: \n  marijuana description \nin the lyrics(%, 95% CI) \n \nAge group')))
```

### Other illicit drug usage

```{r}
songs_abuse %>%
  filter(outcome == "Illicit drugs other than marijuana use in the last month" & lyr_des == "other_illicit") %>%
  mutate(text_label = str_c("Year: ", year,
                            "\nAge group: ", agegrp,
                            "\nIllicit drug other than marijuana use(%, 95% CI): ", round(bsae, 2), " (", round(low_sae, 2)," - ",round(up_sae, 2),")",
                            "\nOther illicit drug description(%, 95% CI):", round(p_lyrics, 2), " (", round(p_lci, 2)," - ",round(p_uci, 2),")")) %>%
  plot_ly(x = ~ year,
          y = ~ bsae,
          color = ~ agegrp,
          text = ~ text_label,
          type = "scatter",
          mode = "paths",
          alpha = 0.7) %>%
  add_ribbons(ymin = ~ low_sae, ymax = ~ up_sae, alpha = 0.3) %>%
  add_trace(x = ~ year, y = ~ p_lyrics, type = "scatter", mode = "paths", text = ~ paste("Other illicit drug description (%): ", round(p_lyrics,2))) %>%
  add_ribbons(ymin = ~ p_lci, ymax = ~ p_uci, alpha = 0.3) %>%
  layout(title = "The relationship between \nother illicit drug usage in the last month and other illicit drug description in the lyrics, \nat national level",
         yaxis = list(title = "Percentage(%)"),
         legend = list(title = list(text = 'Grey line: \n  other illicit drug description \nin the lyrics(%, 95% CI) \n \nAge group')))
```